package com.lzy.srb.sms.reciver;

import com.lzy.srb.base.dto.SmsDTO;
import com.lzy.srb.rabbitutil.constant.MQConst;
import com.lzy.srb.sms.service.SmsService;
import com.lzy.srb.sms.util.SmsProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class SmsReciver {

    @Autowired
    SmsService smsService;

    @RabbitListener(bindings=@QueueBinding(
            value= @Queue(value= MQConst.QUEUE_SMS_ITEM, durable = "true"),
            exchange= @Exchange(value = MQConst.EXCHANGE_TOPIC_SMS),
            key={MQConst.ROUTING_SMS_ITEM}))
    public void send(SmsDTO smsDTO){
        log.info("SmsReciver消息监听");
        Map<String,Object> param = new HashMap<>();
        param.put("code",smsDTO.getMessage());
        smsService.send(smsDTO.getMobile(),
                SmsProperties.TEMPLATE_CODE,
                param
                );
    }

}
